package com.chaber.containers.beans;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "products")
@AttributeOverrides({
	@AttributeOverride(column = @Column(name = "prd_creation_date"), name = "creationDate"),
	@AttributeOverride(column = @Column(name = "prd_modification_date"), name = "modificationDate")
})
public class ProductData extends AbstractObjectData {

	private static final long serialVersionUID = 7795913242507990654L;

	@Id
	@Column(name = "prd_bar_code")
	@NotEmpty
	@Size(min = 1, max = 50)
	private String barCode;
	
	@Column(name = "prd_name")
	@NotEmpty
	@Size(min = 1, max = 50)
	private String name;
	
	@Column(name = "prd_amount")
	@NotNull
	private Integer amount;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "prd_prdcat_id", referencedColumnName = "prdcat_id")
	@NotNull
	private ProductCategoryData assignedCategory;

	@Override
	public Object getId() {
		return this.barCode;
	}

	public String getBarCode() {
		return barCode;
	}

	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	public ProductCategoryData getAssignedCategory() {
		return assignedCategory;
	}

	public void setAssignedCategory(ProductCategoryData assignedCategory) {
		this.assignedCategory = assignedCategory;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("ProductData [barCode=");
		builder.append(barCode);
		builder.append(", name=");
		builder.append(name);
		builder.append(", amount=");
		builder.append(amount);
		builder.append(", assignedCategory=");
		builder.append(assignedCategory);
		builder.append("]");
		return builder.toString();
	}
}
